package com.xxh.mqstudy.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectConfig {


    //声明队列
    @Bean
    public Queue directQueue(){
        return new Queue("myqueue");
    }

    //声明交换机
    @Bean
    public DirectExchange mydirectExchange(){
        return  new DirectExchange("mydirect");
    }

    @Bean
    public DirectExchange noQueueExchange(){
        return new DirectExchange("existNoQueueExchange");
    }

    //绑定队列和交换机,指定他们的路由key
    @Bean
    Binding bindingDirect(){
        return BindingBuilder.bind(directQueue()).to(mydirectExchange()).with("directkey");
    }
}
